﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace BaoJian.eshop.mn
{
    public partial class changePwdApp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ChangePWD_Click(object sender, ImageClickEventArgs e)
        {
            //请确认新密码符合基本规则：密码要求由英文字母(A-Z大小写均可)、阿拉伯数字(0-9)组成且长度为6-16位字符。
            if (!password.Value.Trim().Equals(repeatedPassword.Value.Trim()))
            {
                AlertBox.InnerHtml = "两次输入的新密码不一致。";
                AlertBox.Visible = true;
                return;
            }

            if (Membership.ValidateUser(HttpContext.Current.User.Identity.Name, oldPassword.Value.Trim()))
            {

                MembershipUser user = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                try
                {
                    if (user.ChangePassword(oldPassword.Value.Trim(), password.Value.Trim()))
                    {
                        changePWDDiv.Visible = false;
                        ChangePWDOK.Visible = true;
                    }
                    else
                    {
                        //修改密码出错
                    }
                }
                catch (Exception ex)
                {
                    AlertBox.InnerHtml = ex.Message;
                    AlertBox.Visible = true;
                }
            }
            else
            {
                AlertBox.InnerHtml = "旧密码不正确。";
                AlertBox.Visible = true;
            }
            //MembershipUser user = Membership.GetUser(HttpContext.Current.User.Identity);

        }
    }
}
